﻿@model XSTDZ.ERP.Application.DataContracts.ReceivablePayableRecordDto
@{
    ViewBag.Title = " - 收付款记录";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
 <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
}
<h2>收付款记录</h2>
<div class="wp100">
    @using (Html.BeginForm()) {
        @Html.ValidationSummary(true)
  <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            <input type="hidden" value="@ViewBag.SFBillType" id="SFBillType" name="SFBillType" />
            <input type="hidden" id="HidTotalPay" name="HidTotalPay" value="@ViewBag.AllUnPay" />
             <input type="hidden" id="HidIds" name="HidIds" value="@ViewBag.IDS " />
            </th>
        </tr>
    </thead>
    
    <tr style=" display:@ViewBag.ReveBillNone">
     <td class="title"> @Html.LabelFor(model => model.ReceivedMoney) (元)</td>
        <td> @Html.TextBoxFor(model => model.ReceivedMoney, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.ReceivedMoney)
       
        <input type="hidden" value="@ViewBag.BillId" id="ReceivablePayableBillID" name="ReceivablePayableBillID" />
        
        </td>
        <td class="title">  @Html.LabelFor(model => model.ReceivedMoneyPft) (元)</td>
          <td> @Html.TextBoxFor(model => model.ReceivedMoneyPft, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.ReceivedMoneyPft)
       
        </td>
     </tr>
      <tr style=" display:@ViewBag.PayBillNone">
     <td class="title"> @Html.LabelFor(model => model.PaidMoney) (元)</td>
        <td> @Html.TextBoxFor(model => model.PaidMoney, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.PaidMoney)
        </td>
        <td class="title">  @Html.LabelFor(model => model.OmitMoney)</td>
          <td> @Html.TextBoxFor(model => model.OmitMoney, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.OmitMoney)
       
        </td>
     </tr>






            <tr>
     <td class="title"> @Html.LabelFor(model => model.PayType)</td>
        <td> 
        @Html.DropDownListFor(model => model.PayType, ViewBag.ZFBillType as IEnumerable<SelectListItem>)
        @Html.ValidationMessageFor(model => model.PayType)
        </td>
        <td class="title">  @Html.LabelFor(model => model.Remarks)</td>
          <td> @Html.TextBoxFor(model => model.Remarks, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.Remarks)
       
        </td>
     </tr>  


    
   
       <tr>
        <td  colspan="4">

               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            <input type="hidden" id="hidHttpPostState" name="hidHttpPostState" value="@ViewBag.PostState" />
             <input type="submit" value="" style="display:none;" id="BtnSubmitPost" name="BtnSubmitPost" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"   class="btnStyle" style=" float:right;" id="submitBtn" name="submitBtn" />
           @* <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnClose" id="btnFromClose" name="btnFromClose" class="BtnClose" />*@
    
        </td>
    </tr>
    </table>
    }
    <table class="formtable" style=" margin-top:20px;">
     
     @{var BillModel = ViewBag.BillModel as XSTDZ.ERP.Application.DataContracts.ReceivablePayableBillDto;}
        <input type="hidden" id="HidBillClassify" name="HidBillClassify" value="@BillModel.BillClassify" />
     @if (BillModel.BillClassify)
                             {
         <tr>
                                   <td class="title">总应付款(元)<b>*</b> </td> 
                                   <td id="divBillPayable">@BillModel.BillPayable</td>
                                     <td class="title"> 总应付优惠(元) </td> 
                                 <td id="divBillPayPft">@BillModel.BillPayPft</td>
                                  </tr> 
         <tr>
                                   <td class="title">总已付款(元) </td> 
                                   <td id="divBillPay">@BillModel.BillPay</td>
                                     <td class="title"> 总未付款(元) </td> 
                                 <td id="divUnBillPay">@{var alltotal = @BillModel.BillPayable - (@BillModel.BillPayPft.HasValue?@BillModel.BillPayPft:0) - (@BillModel.BillPay.HasValue? @BillModel.BillPay:0); alltotal = alltotal <= 0 ? 0 : alltotal;} @alltotal</td>
                                  </tr> 
         <tr><td class="title">付款状态：</td><td colspan="3">
          <input type="hidden" id="hidBillState" name="hidBillState" value="@alltotal" />
         @if (alltotal > 0)
                                                         {<b>付款未完成</b>}
                                                         else
                                                         {<b>付款完成</b> }</td></tr>
                             }
     else
     {  <tr>
                                <td class="title"> 总应收款(元) </td> 
                                 <td>@BillModel.BillReceivable</td>
                                 <td class="title"> 总应收优惠(元) </td> 
                                 <td>@BillModel.BillReceivPft</td>
          </tr> 
         <tr>
                                <td class="title"> 总已收款(元) </td> 
                                 <td>@BillModel.BillReceiv</td>
                                 <td class="title"> 总未收款(元) </td> 
                                 <td>@{var allRec = @BillModel.BillReceivable - ( @BillModel.BillReceivPft.HasValue?@BillModel.BillReceivPft:0) - (@BillModel.BillReceiv.HasValue?@BillModel.BillReceiv:0); allRec = allRec <= 0 ? 0 : allRec;} @allRec</td>
          </tr> 
          <tr><td class="title">收款状态：</td><td colspan="3">
           <input type="hidden" id="hidBillState" name="hidBillState" value="@allRec" />
          @if (allRec != 0)
                                                          {<b>收款未完成</b>}
                                                          else
                                                          {<b>收款完成</b> }</td></tr>
        
     }
        
          
    </table>
</div>
<div class="wp100">
<input type="hidden" id="tempId" name="tempId"  value="@ViewBag.TempId" />
<div id="ReceivableItemsGrid" ></div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#submitBtn").unbind("click").bind("click", getProductBillItemData);
        autoDisplay();
    });

    function getProductBillItemData() {
        if (manager != null && manager != undefined) {
            if (!validateData()) { return; }
            var data = manager.getData();
            $("#hidProductBillItems").val("").val(JSON.stringify(data));
            var btnText = $("#submitBtn").val();
            $("#submitBtn").val("").val("正在处理中...");
            $.ajax({ type: "POST", url: "/ReceivablePayable/Edits", data: $('form').serialize(), // 要提交的表单
                success: function (msg) {
                    if (msg == "9") {
                        $.ligerDialog.success('操作成功!');
                        initligerGrid();
                        ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                    }
                    else if (msg == "-2") {
                        $.ligerDialog.success('多项收付款操作，只能全部收付款!');
                    }
                    else if (msg == "-1") {
                        $.ligerDialog.success('入库单明细数据不完整,操作失败!');
                    }
                    else {
                        $.ligerDialog.success('操作失败!');
                    }
                    $("#submitBtn").val("").val(btnText);
                }
            });
        }
    }
    //验证
    function validateData() {
        if ($("#hidBillState").val() == 0) {
            $.ligerDialog.success('已完成收付款，不能再进行操作!');
            return false;
        }
        var numAll = $("#ReceivedMoney").val();
        var num = $("#ReceivedMoneyPft").val();

        if ($("#SFBillType").val() == "1")//付
        {
            numAll = $("#PaidMoney").val();
            num = $("#OmitMoney").val();
        }

        if (isNaN(numAll) || isNaN(num)) {
            $.ligerDialog.success('请输入数字!');
            return false;
        }
        if (numAll <= 0 && num <= 0) {
            $.ligerDialog.success('输入的数字不能同时小于0!');
            return false;
        }



        return true;

    }
    //输入金额，自动显示
    function autoDisplay() {
        //        $("#ReceivedMoney").blur(function () {
        //            changeData($("#ReceivedMoney").val(), true);
        //            //var num = isNaN(("#ReceivedMoney").val()); //判断是否为数字
        //        });
        //        $("#ReceivedMoneyPft").blur(function () { changeData($("#ReceivedMoneyPft").val(), true); });
    }
    function changeData(num, isSK) {
        if (isNaN(num)) {
            $.ligerDialog.success('请输入数字!');
            return;
        }
        if (isSK) {
            $("#divBillPay").val($("#divBillPayable").val() - num - $("#ReceivedMoneyPft").val());

            //$("#divBillPayPft").html($("#divBillPayPft").val()+$("#divBillPayPft").html());
        }

    }

</script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerDateEditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/ProductOutBill/SelectData.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/ReceivablePayable/Add.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>
